#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-5-31 下午8:34
# @Author  : Jason
# @Site    : 
# @File    : image_storage.py
# @Software: PyCharm
from qiniu import Auth,put_data
access_key ='dahEC8bw-oEYgInAkaJfYSJ4BBTHu-whGJZfppUJ'
sercre_key='i-4uy_ykhWwDA4KYXZqcUY8hKRdkuY3UQEhL3SR-'
buck_name = 'heima'

def storage(data):
    try:
        q =Auth(access_key,sercre_key)
        token =q.upload_token(buck_name)
        ret,info=put_data(token,None,data)
        print(ret,info)
    except Exception as e:
        raise e
    if info.status_code !=200:
        raise Exception("上传图片失败")
    return  ret['key']
if __name__ == '__main__':
    file =input("请输入文件路径")
    with open(file,'rb') as f:
        storage(f.read())

